package sunsun.xiaoli.jiarebang.utils;

import com.itboye.pondteam.bean.DeviceListBean;
import org.json.JSONException;
import org.json.JSONObject;
import sunsun.xiaoli.jiarebang.R;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by Administrator (IntelliJ IDEA) on 2018/6/21.
 *
 * @description: xiaolizhineng_android
 */
public class MapToArrayList {
    public static ArrayList<HashMap<String, Object>> buildArrayForMap(ArrayList<DeviceListBean> arrayList, String exclude) {
        ArrayList<HashMap<String, Object>> listItemsTemp = new ArrayList<>();
        for (DeviceListBean deviceListBean : arrayList) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("ItemName", deviceListBean.getDevice_nickname());
            map.put("ItemDid", "DID:" + deviceListBean.getDid());
            map.put("ItemState1", "");
            map.put("ItemState2", "");
            map.put("extra", deviceListBean.getExtra());
            map.put("type", deviceListBean.getDevice_type());
            map.put("ItemStatus", R.drawable.guan);
            map.put("ItemSwitch", "0");
            String pwd = "";
            try {
                JSONObject jsonObject = new JSONObject(deviceListBean.getExtra());
                pwd = jsonObject.getString("pwd");
                if (pwd.isEmpty()) {
                    pwd = "sunsun123456";
                }
            } catch (JSONException e) {
                pwd = "sunsun123456";
            }
            map.put("pwd", "Password:" + pwd);
            map.put("ItemIcon", R.drawable.icon);
            listItemsTemp.add(map);
        }
        return listItemsTemp;
    }

    public static ArrayList<HashMap<String, Object>> buildArrayForMapForBindCamera(ArrayList<DeviceListBean> arrayList, ArrayList<DeviceListBean> arrayListBindedMasterDevice) {
        ArrayList<HashMap<String, Object>> listItemsTemp = new ArrayList<>();
        for (DeviceListBean deviceListBean : arrayList) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("ItemName", deviceListBean.getDevice_nickname());
            map.put("ItemDid", "DID:" + deviceListBean.getDid());
            String isChecked = "0";
            for (DeviceListBean listBean : arrayListBindedMasterDevice) {
                if (deviceListBean.getDid().equals(listBean.getMaster_did())) {
                    isChecked = "1";
                    break;
                }
            }
            map.put("ItemSwitch", isChecked);
            if (isChecked.equals("1")) {
                map.put("ItemStatus", R.drawable.kai);
            } else {
                map.put("ItemStatus", R.drawable.guan);
            }
            map.put("type", deviceListBean.getDevice_type());
            map.put("ItemIcon", R.drawable.icon);
            listItemsTemp.add(map);
        }
        return listItemsTemp;
    }
}
